<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of personal_model
 *
 * @author Neil
 */
class personal_model extends CI_Model {

    public function tiposPersonal() {
        $query = $this->db->query('select id_tipo as codigo, desc_tipo as descripcion from tipo_personal');
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
    }

    public function Personal() {
        $query = $this->db->query('select p.id_pers,p.nom_per,p.ape_per,p.dir_per,p.dni_per,p.tel_per,tp.desc_tipo from personal p inner join tipo_personal tp
                            on p.tipo = tp.id_tipo');
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
    }

    public function regMod($codigo, $data) {
        if ($codigo == '') {
            $this->db->insert('personal', $data);
        } else {
            $this->db->where('id_pers', $codigo);
            $this->db->update('personal', $data);
        }
    }

    public function listarxCod($cod) {
        $query = $this->db->query('SELECT * FROM personal where id_pers=?', $cod);
        return $query->result();
    }

}

?>
